import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {S1Service} from '../../service/s1.service';

@Component({
  selector: 'app-a',
  templateUrl: './a.component.html'
})
export class AComponent implements OnInit {
  getParentStr: string = 'null';
  str: string = '123';
  //父组件传入val
  @Input() val: string = '';
  //子传父数据,通过output
  @Output() sendEvent: EventEmitter<any> = new EventEmitter<any>();


  constructor(public s: S1Service) {
    s.change.subscribe(res => {
      this.getParentStr = res;
    });
  }

  ngOnInit() {
  }

  test() {
    this.str = '456';
  }

  send() {
    this.sendEvent.emit('sendsth');
  }
  siblingSend(){
    this.s.sendMsg('a向b传递数据,这是两个没有关联的组件')
  }

}
